package cn.tansanqinger.DesignMode.Singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

class Message4{
    private Message4(){
        System.out.println("构造方法");
    }
    private static Message4 message4 = null;
    public static Message4 getInstance(){
        if(message4==null){
            message4 = new Message4();
        }
        return message4;
    }
    public void printf(){
        System.out.println("C3H2");
    }
}
public class ReflectSingleton {
    public static void main(String[] args) throws Exception {
        Message4 messageA = Message4.getInstance();
        Class<?> clazz = Message4.class;
        Constructor con = clazz.getDeclaredConstructor(null);
        con.setAccessible(true);
        Object object = con.newInstance();
        Field messageField = clazz.getDeclaredField("message4");
        messageField.setAccessible(true);
        messageField.set(object,null);
        Message4 messageB = Message4.getInstance();
    }
}
